package com.gitee.jiaojinxin.oauth2.client1.controller;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.gitee.jiaojinxin.oauth2.client1.util.AuthenticationUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("tokenVal")
    public String tokenVal(){
        return AuthenticationUtil.tokenVal();
    }

    @GetMapping("hello")
    public String hello(){
        String accessToken = AuthenticationUtil.tokenVal();
        HttpResponse response = HttpRequest.get("http://localhost:8002/resource1/hello")
                .header("Authorization", "Bearer " + accessToken)
                .execute();
        if (!response.isOk()) {
            return "查询失败";
        }
        return response.body();
    }
}
